<template>
  <div>

    <van-row>
      <van-col span="6"><Lef></Lef></van-col>
      <van-col span="18">
        <van-row>
          <van-col span="24"><headers></headers></van-col>
        </van-row>
        <van-row>
          <p v-for="i in paramslist" :key="i.id">
            <van-field v-if="i.type=='input'" :label="i.label" type="sdate" v-model="values[i.label]"/>
            <br>
            <select v-if="i.type=='select'" v-model="values[i.label]">
              <option :value="t.type" v-for="t in i.value" :key="t.id">{{ t.name }}</option>
            </select>
            <br>
            <van-field v-if="i.type=='rideo'" label="性别">
              <template #input>
                <van-radio-group v-model="values[i.label]" direction="horizontal">
                  <van-radio name="男">男</van-radio>
                  <van-radio name="女">女</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <br>
            <van-uploader v-if="i.type=='file'" :after-read="uplode">文件上传</van-uploader>
            <br>
            <el-date-picker v-if="i.type=='sdate'"
                            v-model="value1"
                            type="datetimerange"
                            range-separator="To"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            value-format='YYYY-MM-DD HH:mm:ss'
            >
            </el-date-picker>
            <br>
          </p>
          <span v-if="pic.length>1"><img :src="pic" alt="" width="150" height="250"></span>

        </van-row>
        <van-row>
          <van-button @click='getaudit'>选择审批人</van-button>

          <el-dialog v-model="dialogTableVisible" title="Shipping address">
            <el-tree
                :data="data"
                show-checkbox
                node-key="id"
                :props="defaultProps"
                @check-change='getids'
            />
          </el-dialog>
          <van-button @click='submit'>提交</van-button>
        </van-row>


      </van-col>
    </van-row>


  </div>
</template>

<script>
import myaxios from "@/http/axios";
import axios from "axios";
import Lef from "@/components/veiw/lef";
import Headers from "@/components/veiw/headers";
export default {
  name: "eadittask",
  components: {Headers, Lef},
  data() {
    return {
      data1: '',
      paramslist: [],
      workff: {},
      id: this.$route.query.id,
      value1: [],
      values:{},
      pic:'',
      checkdvalues:[],
      dialogTableVisible:false,
      data: [
      ],
      defaultProps: {
        children: 'children',
        label: 'name',
      },
      list:[],
      taskid:this.$route.query.taskid,

    }
  },
  methods: {
    get_params() {
      myaxios('getparams?id=' + this.id, 'get').then(res => {
        this.workff = res.list
        this.paramslist = JSON.parse(res.list.params)
      })
    },
    getlabel(type){
      let label = ''
      for (var i=0;i<this.paramslist.length;i++){
        if (this.paramslist[i]['type'] == type){
          label = this.paramslist[i]['label']
        }
      }
      return label
    },
    getaudit(){
      //读取公司部门角色列表
      myaxios('getcomanyuser','get').then(res=>{
        this.data = res.list
      })
      this.dialogTableVisible=true
    },

    getids(data){
      // let list=[]
      if (data.type==3){
        this.list.push(data.id)
      }
      console.log(this.list)
      // this.checkdvalues=[]
      // let list = status['checkedNodes']
      // for(var i=0;i<list.length;i++){
      //   if(list[i]['type'] == 3){
      //     console.log(i)
      //     this.checkdvalues.push(list[i]['id'])
      //   }
      // }
    },
    submit(){
      if(this.pic){
        let label = this.getlabel('file')
        this.values[label] = this.pic
      }
      if(this.value1.length>0){
        let stime = this.getlabel('sdate')
        this.values[stime] = this.value1[0]
        this.values['结束时间'] = this.value1[1]
      }
      //获取第一个input框中的信息
      let name = document.getElementsByTagName('input')[0].value
      let title = name+this.workff['name']
      console.log(this.checkdvalues)
      myaxios('taskm','post',{'title':title,'params':JSON.stringify(this.values),'auditids':this.list}).then(res=>{
        alert(res.msg)
      })
      console.log(title)
      console.log(this.values)
      console.log(this.checkdvalues)
    },
    may(value){
      const mydate = String(value).split(" ")
// console.log(mydate[3],mydate[1],mydate[2])
      if(mydate[1]=="Jan"){
        mydate[1]="01"
      }else if(mydate[1]=="Feb"){
        mydate[1]="02"
      } else if(mydate[1]=="Mar"){
        mydate[1]="03"
      }else if(mydate[1]=="Apr"){
        mydate[1]="04"
      }else if(mydate[1]=="Mar"){
        mydate[1]="05"
      }else if(mydate[1]=="Jun"){
        mydate[1]="06"
      }else if(mydate[1]=="Jul"){
        mydate[1]="07"
      }else if(mydate[1]=="Aug"){
        mydate[1]="08"
      }else if(mydate[1]=="Sep"){
        mydate[1]="09"
      }else if(mydate[1]=="Oct"){
        mydate[1]="10"
      }else if(mydate[1]=="Nov"){
        mydate[1]="11"
      }else if(mydate[1]=="Dec"){
        mydate[1]="12"
      }
      return mydate[3] + "-" + mydate[1] + "-" + mydate[2]
    },
    uplode(file){
      let formdate = new FormData()
      formdate.append('file',file.file)
      console.log(formdate)
      axios({url:'http://127.0.0.1:5000/imgfile',method:'post',data:formdate}).then(res=>{
        this.pic = res.data.list
      })
    },
    //根据taskid查找任务
    gettask(){
      myaxios('mytaskhandle?id='+this.taskid,'get').then(res=>{
        let params = JSON.parse(res.list['params'])
        this.values = params
        this.pic = params['亲家凭证']
        this.value1[0]=params['时间']
        this.value1[1]=params['结束时间']
      })
    }
  },
  mounted() {
    this.get_params()
    this.gettask()
  }
}
</script>

<style scoped>

</style>